#include "adddialog.h"

#include <QColorDialog>

AddDialog::AddDialog ( QStringList lifeList, QWidget *parent ) : QDialog ( parent )
{
	setupUi ( this );

	lifeListWidget -> addItems ( lifeList );

	connect ( okButton, SIGNAL ( clicked() ), this, SLOT ( accept() ) );
	connect ( cancelButton, SIGNAL ( clicked() ), this, SLOT ( reject() ) );
	connect ( colorBtn, SIGNAL ( clicked() ), this, SLOT ( setColor() ) );
	connect ( lifeListWidget, SIGNAL( itemClicked(QListWidgetItem*) ), this, SLOT( updateColor(QListWidgetItem*) ) );
}

int AddDialog::getNumber()
{
	return numberSpin -> value();
}

QString AddDialog::getLife()
{
	return ( lifeListWidget -> currentItem() ) -> text();
}

void AddDialog::setColor()
{
	color = QColorDialog::getColor ( color, this );

	colorLbl -> setText ( color.name() );
	colorLbl -> setPalette ( QPalette ( color ) );
	colorLbl -> setAutoFillBackground ( true );
}

void AddDialog::updateColor(QListWidgetItem* currentItem)
{
	if ( ( currentItem -> text() ) == "Animal" ) color = Qt::red;
	else if ( ( currentItem -> text() ) == "Gravity" ) color = Qt::green;

	colorLbl -> setText ( color.name() );
	colorLbl -> setPalette ( QPalette ( color ) );
	colorLbl -> setAutoFillBackground ( true );
}

QColor AddDialog::getColor()
{
	return color;
}
